# -*- coding: utf-8 -*-
"""
三角形计算工具
功能：根据输入的三边长度判断能否构成三角形，并计算周长和面积

@author: lengf
@date: 2025-04-14
@email: lengfo@163.com
@version: 1.1.0
"""

import math

def is_triangle(a, b, c):
    """判断三边能否构成三角形"""
    return a + b > c and a + c > b and b + c > a

def calculate_triangle(a, b, c):
    """计算三角形的周长和面积"""
    perimeter = a + b + c
    p = perimeter / 2
    area = math.sqrt(p * (p - a) * (p - b) * (p - c))
    return perimeter, area

def main():
    try:
        a = float(input('请输入边长a: '))
        b = float(input('请输入边长b: '))
        c = float(input('请输入边长c: '))
        
        if a <= 0 or b <= 0 or c <= 0:
            raise ValueError("边长必须为正数")
            
        if is_triangle(a, b, c):
            perimeter, area = calculate_triangle(a, b, c)
            print(f'周长: {perimeter:.2f}')
            print(f'面积: {area:.2f}')
        else:
            print('不能构成三角形')
    except ValueError as e:
        print(f'输入错误: {e}')

if __name__ == '__main__':
    main()
